package cn.echo.modules.sys.controller.areacontroller;


import cn.echo.modules.sys.entity.Area;
import cn.echo.modules.sys.service.AreaService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 王飞
 * @Date 2017-4-19
 * @version 1.1
 */
@Controller
@RequestMapping("area")
public class AreaController {
    @Autowired
    private AreaService areaService;
    @RequestMapping(value = "show",method = RequestMethod.GET)
    public String show(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                       @RequestParam(required = false,defaultValue = "5") Integer pageSize,
                       Model model){
        //AreaService areaService = new AreaService();
        PageHelper.startPage(pageNum,pageSize);
        Page<Area> areaList = (Page) areaService.findAll(new Area());
        PageInfo<Area> pageInfo = new PageInfo(areaList);
        model.addAttribute("page",pageInfo);
        return "sys/area/areaList";
    }
    @RequestMapping(value = "startUpdate",method = RequestMethod.GET)
    public String startUpdate(String id,Model model){
        model.addAttribute("id",id);
        return "sys/area/areaChange";
    }
    @RequestMapping(value = "endUpdate",method = RequestMethod.POST)
    public String endUpdate(String id, String cmbProvince, String cmbCity,
                            String cmbArea,Model model)
    {
       // AreaService areaService=new AreaService();
        areaService.update(id,cmbProvince,cmbCity,cmbArea);
        return "redirect:/area/show";
    }
    @RequestMapping(value = "delete",method = RequestMethod.GET)
    public String delete(String id)
    {
       // AreaService areaService=new AreaService();
        areaService.delete(id);
        return "redirect:/area/show";
    }
}
